home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / tcp / mufs_telnetd.lha / telnetd2_0.lha / telnetd-2.0 / source / fakesr / devinit.c < prev    next >
C/C++ Source or Header  |  1995-01-15  |  6KB  |  172 lines

  1. /* #define  _USEOLDEXEC_ 1 */
  2. #include <exec/types.h>
  3. #include <exec/nodes.h>
  4. #include <exec/memory.h>
  5. #include <exec/resident.h>
  6. #include <exec/libraries.h>
  7. #include <exec/devices.h>
  8. #include <libraries/dos.h>
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11. #include <string.h>
  12. #include <dos.h>
  13.  
  14. #include "fakesr.h"
  15. #include "fakesrprivate.h"
  16.  
  17. typedef LONG (*PFL)();   /* pointer to function returning 32-bit int        */
  18. #define DEBUGBREAK() __emit(0x4afc)
  19.  
  20. struct Library *SysBase;
  21.  
  22. /* library initialization table, used for AUTOINIT libraries                */
  23. struct InitTable {
  24.         ULONG        *it_DataSize;       /* library data space size         */
  25.         PFL          *it_FuncTable;      /* table of entry points           */
  26.         APTR         it_DataInit;        /* table of data initializers      */
  27.         PFL          it_InitFunc;        /* initialization function to run  */
  28. };
  29.  
  30.  
  31. /* symbols generated by blink */
  32. extern char __far _LibID[];             /* ID string                        */
  33. extern char __far _LibName[];           /* Name string                      */
  34. extern char __far RESLEN;               /* size of init data                */
  35. extern long __far NEWDATAL;             /* size of global data              */
  36. extern PFL _LibFuncTab[];               /* my function table                */
  37. #define DATAWORDS ((long)&NEWDATAL)     /* magic to get right tpye of reloc */ 
  38. #define SIZEJMPTAB ((long)libbase->fsd_origbase->fsd_numjmps)
  39.                                         /* size in bytes of jmp table       */
  40. #define MYREVISION 0                    /* revision number                  */
  41.  
  42. /* From libent.o, needed to determine where data is loaded by loadseg       */
  43. extern long far _Libmergeddata; 
  44.  
  45.  
  46. struct InitTable __far _LibInitTab =  {
  47.         (long *)(&RESLEN+sizeof(struct FakeSerDevice)),
  48.         _LibFuncTab,
  49.         NULL,                        /* will initialize my own data */
  50.         _LibInit,
  51. };
  52.  
  53. __saveds __asm
  54. ULONG _LibInit( register __a0 APTR seglist,
  55.         register __d0 struct FakeSerDevice *libbase )
  56. {
  57.     long *reloc;
  58.     long *sdata;
  59.     char *ddata;
  60.     long nrelocs;
  61.         void *SysBase;
  62.  
  63.     SysBase=*((void **)0x00000004);
  64.     libbase->fsd_SegList = (ULONG) seglist;
  65.  
  66.         /* DEBUGBREAK();*/
  67.     /* init. library structure (since I don't do automatic data init.) */
  68.     libbase->fsd_Dev.dd_Library.lib_Node.ln_Type = NT_DEVICE;
  69.     libbase->fsd_Dev.dd_Library.lib_Node.ln_Name =  _LibName;
  70.     libbase->fsd_Dev.dd_Library.lib_Flags = 0; /* LIBF_SUMUSED | LIBF_CHANGED;*/
  71.     libbase->fsd_Dev.dd_Library.lib_Version = 1;
  72.     libbase->fsd_Dev.dd_Library.lib_Revision = MYREVISION;
  73.     libbase->fsd_Dev.dd_Library.lib_IdString = (APTR) _LibID;
  74.  
  75.      /* Start of copy of global data after structure */
  76.     ddata = (char *)libbase + sizeof(struct FakeSerDevice); 
  77.  
  78.     sdata = (long *)&_Libmergeddata; /* where loadseg loaded the data */
  79.     memcpy(ddata, (void *)sdata, DATAWORDS*4);
  80. /*        KPrintF("DATAWORDS=%ld\n",(long)DATAWORDS);*/
  81.     /* perform relocs if we want one global section for all programs */
  82.     /* that have this lib open. If we want a global section for each */
  83.     /* open, copy the relocs, and do them on each open call.         */
  84.     sdata = sdata + DATAWORDS;
  85.     nrelocs = *sdata;
  86.     sdata++;
  87. /*        KPrintF("sdata=%lx\n",(long)sdata);
  88.         KPrintF("nrelocs=%ld\n",(long)nrelocs);
  89.         DEBUGBREAK();
  90.     while (nrelocs > 0)
  91.     {
  92.        reloc = (long *)((long)ddata + *sdata++);
  93.        *reloc += (long)ddata;
  94.        nrelocs--;
  95.     }*/
  96.     _UserLibInit(libbase);
  97.         /*DEBUGBREAK();*/
  98.     return ( (ULONG) libbase );
  99. }
  100.  
  101. LONG __saveds __asm
  102. _LibOpen( register __a6 struct        FakeSerDevice *libbase, register __a1 void *IORequest, register __d0 LONG UnitNum, register __d1 ULONG Flags)
  103. {
  104.         void *SysBase;
  105.  
  106.     SysBase=*((void **)0x00000004);
  107.         /* DEBUGBREAK(); */
  108.     /* mark us as having another customer */
  109.     libbase->fsd_Dev.dd_Library.lib_OpenCnt++;
  110.         
  111.         
  112.     /* clear delayed expunges (standard procedure)                */
  113.     libbase->fsd_Dev.dd_Library.lib_Flags &= ~LIBF_DELEXP;
  114.         ((struct IORequest *)IORequest)->io_Error=0;
  115.         _UserLibOpen(libbase,IORequest,UnitNum,Flags);
  116.         if (((struct IORequest *)IORequest)->io_Error) {
  117.             /* Error */
  118.             libbase->fsd_Dev.dd_Library.lib_OpenCnt--;
  119.         }
  120.     /*        DEBUGBREAK();*/
  121.     return ( (LONG) libbase );
  122. }
  123.  
  124. ULONG __saveds __asm
  125. _LibClose( register __a6 struct FakeSerDevice *libbase,register __a1 void *IORequest)
  126. {
  127.     ULONG retval = 0;
  128.         void *SysBase;
  129.  
  130.     SysBase=*((void **)0x00000004);
  131.     
  132.         _UserLibClose(libbase,IORequest);
  133.     if (( --libbase->fsd_Dev.dd_Library.lib_OpenCnt == 0 ) &&
  134.                         ( libbase->fsd_Dev.dd_Library.lib_Flags & LIBF_DELEXP ))
  135.     {
  136.         /* no more people have me open,
  137.          * and I have a delayed expunge pending
  138.          */
  139.          retval = _LibExpunge( libbase ); /* return segment list        */
  140.     }
  141.     return (retval);
  142. }
  143.  
  144. ULONG __saveds __asm
  145. _LibExpunge( register __a6 struct FakeSerDevice *libbase )
  146. {
  147.     ULONG seglist = 0;
  148.     LONG  libsize;
  149.         void *SysBase;
  150.  
  151.     SysBase=*((void **)0x00000004);
  152.  
  153.     libbase->fsd_Dev.dd_Library.lib_Flags |= LIBF_DELEXP;
  154.     if ( libbase->fsd_Dev.dd_Library.lib_OpenCnt == 0 )
  155.     {
  156.         /* really expunge: remove libbase and freemem        */
  157.         _UserLibCleanup(libbase);
  158.         seglist = libbase->fsd_SegList;
  159.  
  160.         Remove( (struct Node *) libbase);
  161.  
  162.         libsize = libbase->fsd_Dev.dd_Library.lib_NegSize + libbase->fsd_Dev.dd_Library.lib_PosSize;
  163.         FreeMem( (char *) libbase - libbase->fsd_Dev.dd_Library.lib_NegSize,(LONG) libsize );
  164.     }
  165.  
  166.     /* return NULL or real seglist                                */
  167.     return ( (ULONG) seglist );
  168. }
  169.  
  170.  
  171.  
  172.